package com.yonyou.pmclouds.workflow.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.entity.ProcessDefinitionVO;
import com.yonyou.pmclouds.workflow.mapper.ProcessDefinitionMapper;

public class ProcessStatusCheck implements SingleProcessor<ProcessDefinitionVO> {

    private ProcessDefinitionMapper definitionMapper;

    public ProcessStatusCheck(ProcessDefinitionMapper definitionMapper) {
        this.definitionMapper = definitionMapper;
    }

    @Override
    public void process(ProcessDefinitionVO vo, ProcessDefinitionVO orig) throws BusinessException {
        if(ProcessDefinitionVO.PROCESS_STATUS_START.equalsIgnoreCase(vo.getProcessStatus())) {
            ProcessDefinitionVO[] definitionVOS = definitionMapper.getStartProcessByType(vo.getPkTenant(), vo.getBillType(), vo.getPkOrg());
            if(definitionVOS != null && definitionVOS.length > 0) {
                throw new BusinessException("单个单据只允许启用一个审批流");
            }
        }
    }
}
